package org.barad.architecture.analyzer.archpad.component;

import java.util.LinkedHashSet;

import org.barad.architecture.analyzer.archpad.persistence.PersistenceManager;
import org.barad.architecture.analyzer.archpad.region.Region;

/**
 * This class represents the base of an ArchPad component.
 *  
 * @author svetoslavganov@gmail.com (Svetoslav R. Ganov)
 *
 */
public abstract class AcrhPadBasicComponent {
	static {
		PersistenceManager.makeTransient(AcrhPadBasicComponent.class, "regions");
	}
	
	protected LinkedHashSet<Region> regions;
	protected String templateFileName;

	/**
	 * Creates a new instance.
	 */
	public AcrhPadBasicComponent() {
		this.regions = new LinkedHashSet<Region>();
	}
	
	/**
	 * @see Object#clone()
	 */
	@Override
	public Object clone() {
		AcrhPadBasicComponent clone = null;
		try {
			clone = (AcrhPadBasicComponent)super.clone();
			//do not clone the regions since they will not be edited
			clone.regions = regions;
			clone.templateFileName = templateFileName;
		} catch (CloneNotSupportedException cnse) {
			throw new InternalError();
		}
		return clone;
	}
	
	/**
	 * Gets the {@link Region}s to which the component belongs.
	 * 
	 * @return The {@link Region}s.
	 */
	public LinkedHashSet<Region> getRegions() {
		return regions;
	}

	/**
	 * Sets the {@link Region}s to which the component belongs.
	 * 
	 * @param regions The {@link Region}s.
	 */
	public void setRegions(LinkedHashSet<Region> regions) {
		this.regions = regions;
	}
	
	/**
	 * Gets the name of the template file which defines the component.
	 * 
	 * @return The file name.
	 */
	public String getTemplateFileName() {
		return templateFileName;
	}

	/**
	 * Sets the name of the template file which defines the component.
	 *  
	 * @param templateFileName The file name.
	 */
	public void setTemplateFileName(String templateFileName) {
		this.templateFileName = templateFileName;
	}
}
